<?php
require_once 'hello_madal_db_mvc/Model/model_require_once.php';
require_once 'hello_madal_db_mvc/View/Includes/view_require_once.php';
?>
<script type="text/javascript">
<?php
require_once 'hello_madal_db_mvc/Model/hello_madal_db_javascript_classes.min.js';
?>

function refreshPage(){
	//simple (but ineffient) way to get the new data
	window.location.reload();
}
</script>

<title>Hello MADAL World</title>

<h1>Hello MADAL World</h1>
<?php

Make::print_Make_add ( "refreshPage" );

$makes = Make::getMakes ();
$models = Model::getModels ();

?>
<script type="text/javascript">
var make_id = 1;
function selectMakeId(selectedMakeId){
	make_id = selectedMakeId;
}

var model_id = 1;
function selectModelId(selectedModelId){
	model_id = selectedModelId;
}
</script>
<!-- Examples of a madal formatted adders -->
<?php Model::print_Model_add("refreshPage", true, Make::FIELD_ID_MAKE_NAME);?>

<?php Car::print_Car_add("refreshPage", true, Model::FIELD_ID_MODEL_NAME); ?>

<?php

Make::instantiate_javascript_objects ( $makes );

?>
<h2>Makes</h2>
<table>
	<tr>
		<th>Make Id</th>
		<th>Name</th>
	</tr>
<?php
/* @var $make Make */
foreach ( $makes as $make ) {
	?>
	<tr>
		<td><?php
	echo $make->get_make_id ();
	?></td>
		<td><?php
	$make->print_make_name_input_setter ();
	?></td>
		<td>
	<?php
	$make->print_delete_button ( true, "refreshPage" );
	?>
	</td>
	</tr>
<?php
}
?>
</table>

<?php

Model::instantiate_javascript_objects ( $models );

?>
<h2>Models</h2>
<table>
	<tr>
		<th>Model Id</th>
		<th>Name</th>
		<th>Make</th>
	</tr>
<?php
/* @var $model Model */
foreach ( $models as $model ) {
	?>
	<tr>
		<td><?php
	echo $model->get_model_id ();
	?></td>
		<td><?php
	$model->print_model_name_input_setter ();
	?></td>
		<td>
	<?php
	echo $model->getMake ()->get_make_name ();
	?></td>
		<td>
	<?php
	$model->print_delete_button ( true, "refreshPage" );
	?>
	</td>
	</tr>
<?php
}
?>
</table>

<?php

$cars = Car::getCars ();
Car::instantiate_javascript_objects ( $cars );

?>
<h2>Cars</h2>
<table>
	<tr>
		<th>Car Id</th>
		<th>Color</th>
		<th>Make</th>
		<th>Model</th>
		<th>Manufacture Date</th>
	</tr>
<?php
/* @var $car Car */
foreach ( $cars as $car ) {
	?>
	<tr>
		<td><?php
	echo $car->get_car_id ();
	?></td>
		<td><?php
	$car->print_color_input_setter ();
	?></td>
		<td><?php
	echo $car->getModel ()->getMake ()->get_make_name ();
	?></td>
		<td><?php
	echo $car->getModel ()->get_model_name ();
	?></td>
	<td>
	<?php $car->print_manufacture_date_input_setter(); ?>
	</td>
		<td>
	<?php
	$car->print_delete_button ( true, "refreshPage" );
	?>
	</td>
	</tr>
<?php
}
?>
</table>
<script type="text/javascript">
$(
function(){
	pageLoaded();
}
		);
</script>

